package com.itdianzi.service.cargo.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itdianzi.dao.cargo.ContractDao;
import com.itdianzi.domain.cargo.Contract;
import com.itdianzi.domain.cargo.ContractExample;
import com.itdianzi.domain.vo.ContractProductVo;
import com.itdianzi.service.cargo.ContractService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import java.util.UUID;


@Service
public class ContractServiceImpl implements ContractService {
    @Autowired
    private ContractDao contractDao;
    @Override
    public Contract findById(String id) {

        return contractDao.selectByPrimaryKey(id);
    }

    @Override
    public void save(Contract contract) {


        System.out.println(contract);
        //1.页面传入参数 但是不全  需要我们手动补充
        contract.setTotalAmount(0d);
        contract.setState(0);//草稿的数据可以删除  ,上报 提交给领导了   报运(给海关)
        //2.要保存到数据库 需要有id
        contract.setId(UUID.randomUUID().toString());
        contract.setProNum(0);//货物数量
        contract.setExtNum(0);//附件数量
        /*contract.setCreateTime(new Date());*///数据创建的日期 - 数据排序

        contractDao.insertSelective(contract);
    }

    @Override
    public void update(Contract contract) {
        contractDao.updateByPrimaryKeySelective(contract);
    }

    @Override
    public void delete(String id) {
        contractDao.deleteByPrimaryKey(id);

    }

    @Override
    public PageInfo findAll(ContractExample example, int page, int size) {
        PageHelper.startPage(page, size);
        List<Contract> contracts = contractDao.selectByExample(example);

        return new PageInfo(contracts);
    }

    @Override
    public List<ContractProductVo> findByShipTime(String inputDate, String companyId) {
        return contractDao.findByShipTime(inputDate, companyId);
    }


    @Override
    public List<Contract> findAll(){

        ContractExample contractExample = new ContractExample();
        List<Contract> contracts = contractDao.selectByExample(contractExample);
        return contracts;
    }

}
